

#ifndef _BasicTools_DEFINED
#define _BasicTools_DEFINED

#include <stdio.h>

/* BASIC TYPES */

typedef enum {false, true} Boolean;

typedef void * OBJECT;

/* EXECUTION TRACE AND DEBUGGING */

#undef IGNORE

#define WW  __FILE__, __LINE__,
#define WW0 __FILE__, __LINE__
#define ww  char *who, int where, 
#define ww0 char *who, int where

#define MALLOC(s)         mem_alloc(__FILE__,__LINE__,s)
#define FREE(p)           finish(__FILE__,__LINE__,p)
#define FINISH_MALLOC()   finish_all(true)

#define trace fprintf(stderr, "%s:%d trace:\n", WW); fflush(stderr);
#define trace_int(x) \
   fprintf(stderr, "%s:%d value: %d\n", WW, x); \
   fflush(stderr);
#define trace_name(x) \
   fprintf(stderr, "%s:%d name: %s\n", WW, x); \
   fflush(stderr);

/* ERROR HANDLING AND COMMUNICATIONS */

void Error(const char *who, int where, const char *fmt, ...);
void Warning(const char *who, int where, const char *fmt, ...);
void Message(const char *fmt, ...);

/* RESOURCE MANAGEMENT */

/* allocate memory */
void *mem_alloc(const char *who, int where, size_t size);

/* open file */
FILE *file_open(const char *who, int where, const char *fname, const char *mode);

/* free resource `p' */
void finish (const char *who, int where, void *p);

/* complete resource deallocation at end of job */
void finish_all(Boolean check);

/* UTILITIES */

/* duplicates a string */
char *str_dup (const char *who, int where, const char *src);

/* concatenates two strings */
char *str_cat(char *who, int where, char *s, char *t);

#endif
